<?php

class AuthUserBehavior extends CBehavior
{
    public function getAuth()
    {
        return Yii::app()->authManager;
    }
    
    public function getAuthItemNamesList($type)
    {
        $authItems = $this->getAuth()->getAuthItems($type, $this->getOwner()->getId());
        if(empty($authItems))
            return '';
        else
        {
            $items = array();
            foreach($authItems as $itemName => $authItem)
                $items[] = CHtml::link($itemName, array('authItem/update', 'itemName'=>$itemName));
            
            return implode(', ', $items);
        }    
    }
    
    public function getAssignmentOperations()
    {
        return $this->getAuthItemNamesList(CAuthItem::TYPE_OPERATION);
    }
    
    public function getAssignmentTasks()
    {
        return $this->getAuthItemNamesList(CAuthItem::TYPE_TASK);
    }
    
    public function getAssignmentRoles()
    {
        return $this->getAuthItemNamesList(CAuthItem::TYPE_ROLE);
    }
    
    public function getAssignmentLink()
    {
        return CHtml::link($this->getOwner()->username, array('assignment/user', 'id'=>$this->getOwner()->getId()));
    }
}